package cn.com.tom.dao.impl;

import cn.com.tom.bean.Website;
import cn.com.tom.dao.WebsiteDao;
import cn.com.tom.dao.impl.BaseDaoImpl;
import cn.com.tom.util.Dbs;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.ArrayList;
import java.util.List;

public class WebsiteDaoImpl extends BaseDaoImpl<Website> implements WebsiteDao {

    public boolean save(Website website) {
        Integer id = website.id;
        String sql = "";
        List<Object> args = new ArrayList<>();
        if (id == null || id < 1) {
            sql = "INSERT INTO website(footer) VALUES(?)";
            args.add(website.footer);
        } else {
            sql = "UPDATE website SET footer=? WHERE id=?";
            args.add(website.footer);
            args.add(id);
        }
        return Dbs.save(sql, args.toArray());
    }

    public Website get(Integer id) {
        return null;
    }

    public List<Website> list() {
        String sql = "SELECT id,created_time,footer FROM website";
        return Dbs.list(sql, new BeanPropertyRowMapper<>(Website.class));
    }
}
